home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
unix
/
c
/
pipe
< prev
next >
Wrap
Text File
|
1996-11-09
|
2KB
|
132 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/pipe,v $
* $Date: 1996/10/30 22:04:51 $
* $Revision: 1.3 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: pipe,v $
* Revision 1.3 1996/10/30 22:04:51 unixlib
* Massive changes made by Nick Burret and Peter Burwood.
*
* Revision 1.2 1996/05/06 09:01:35 unixlib
* Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
* Saved for 3.7a release.
*
* Revision 1.1 1996/04/19 21:35:27 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: pipe,v 1.3 1996/10/30 22:04:51 unixlib Rel $";
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/os.h>
#include <sys/dev.h>
#include <sys/swis.h>
#include <sys/unix.h>
#include <sys/syslib.h>
int
pipe (int *p)
{
struct pipe *pi;
struct file *f0, *f1;
int fd0, fd1;
char file[32];
int pcnt;
if ((fd0 = __fdalloc ()) < 0)
return (-1);
f0 = __u->file + fd0;
f0->dup = f0;
if ((fd1 = __fdalloc ()) < 0)
{
f0->dup = 0;
return (-1);
}
f1 = __u->file + fd1;
f0->dup = f1;
f1->dup = f0;
{
register char *s = file;
register char *s2 = "/pipe/";
register int i;
char n[11];
while (*s++ = *s2++);
s--;
pcnt = i = __intenv ("UnixLib$pcnt", 0);
s2 = n + 10;
*s2-- = 0;
do
{
*s2-- = (i % 10) + '0';
i /= 10;
}
while (i);
s2++;
while (*s++ = *s2++);
}
f0->oflag = O_RDWR | O_CREAT | O_TRUNC | O_PIPE;
{
int i;
if ((i = __funcall ((*(__dev[DEV_PIPE].open)), (file, 0777, f0))) < 0)
{
f0->dup = f1->dup = 0;
return (-1);
}
f0->dev = f1->dev = makedev (DEV_PIPE, i);
}
{
int r[10];
int v[1];
v[0] = pcnt + 1;
r[0] = (int) "UnixLib$pcnt";
r[1] = (int) v;
r[2] = 4;
r[3] = 0;
r[4] = 1;
os_swi (OS_SetVarVal, r);
}
f0->oflag = O_RDONLY | O_PIPE;
f1->oflag = O_WRONLY | O_PIPE;
f0->pid = f1->pid = __u->pid;
if (!(pi = malloc (sizeof (struct pipe))))
{
close (fd0);
close (fd1);
return (-1);
}
pi->p[0] = f0;
pi->p[1] = f1;
if (!(pi->file = __permstr (file)))
{
close (fd0);
close (fd1);
free (pi);
return (-1);
}
pi->next = __pipe;
__pipe = pi;
p[0] = fd0;
p[1] = fd1;
return (0);
}